package com.zhihuichongcheng.application.ui.main.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hyphenate.chat.EMConversation;
import com.hyphenate.util.DateUtils;
import com.zhihuichongcheng.application.R;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by 3water on 2016/10/27.
 */

public class ConversationAdapter extends RecyclerView.Adapter<ConversationAdapter.ViewHold> {
    private Context mContext;
    private List<EMConversation> mListData = new ArrayList<>();
    public ConversationAdapter(Context context)
    {
        this.mContext = context;
    }

    @Override
    public ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.listadapter_chat_conversation,null);
        return new ViewHold(view);
    }

    @Override
    public void onBindViewHolder(ViewHold holder, int position) {
        EMConversation conversation = mListData.get(position);
        holder.mTvName.setText(conversation.getUserName());
        holder.mTvTime.setText(DateUtils.getTimestampString(new Date(conversation.getLastMessage().getMsgTime())));
//        holder.mTvContent.setText(EaseSmileUtils.getSmiledText(getContext(), EaseCommonUtils.getMessageDigest(lastMessage, (this.getContext())));
    }

    @Override
    public int getItemCount() {
        return mListData.size();
    }

    public void setData(List<EMConversation> list) {
        mListData.addAll(list);
    }

    class ViewHold extends RecyclerView.ViewHolder{
        private ImageView mImAvatar;
        private TextView mTvName,mTvTime,mTvContent;
        public ViewHold(View itemView) {
            super(itemView);
            mImAvatar = (ImageView)itemView.findViewById(R.id.im_avatar);
            mTvName = (TextView)itemView.findViewById(R.id.tv_name);
            mTvContent = (TextView)itemView.findViewById(R.id.tv_content);
            mTvTime = (TextView)itemView.findViewById(R.id.tv_time);
        }
    }
}
